package com.zsy.petshop_01.controller;

import com.zsy.petshop_01.common.result.ResponseResult;
import com.zsy.petshop_01.model.vo.Pet.PetUpdateVo;
import com.zsy.petshop_01.model.vo.Pet.PetVo;
import com.zsy.petshop_01.model.vo.Pet.SubscribeCheckVo;
import com.zsy.petshop_01.model.vo.Pet.UpvoteVo;
import com.zsy.petshop_01.service.PetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Api(tags = "宠物信息管理")
@RestController
@RequestMapping("/pet")
public class PetController {
    @Autowired
    PetService petService;

    @ApiOperation("搜索所有宠物信息")
    @GetMapping("/selectAllPet")
    public ResponseResult<?> selectAllPet(){
        return petService.selectAllPet();
    }

    @ApiOperation("删除宠物信息")
    @PostMapping("/delete")
    public ResponseResult<?> deletePet(@RequestParam("id") Integer id){
        return petService.deletePet(id);
    }

    @ApiOperation("添加宠物信息")
    @PostMapping("/insertPet")
    public ResponseResult<?> insetPet(PetVo petVo){
        return petService.insetPet(petVo);
    }

    @ApiOperation("更新宠物信息")
    @PostMapping("/updatePet")
    public ResponseResult<?> updatePet(PetUpdateVo petUpdateVo){
        return petService.updatePet(petUpdateVo);
    }

    @ApiOperation("查询宠物信息")
    @GetMapping("/selectPet")
    public ResponseResult<?> selectPet(@RequestParam(value = "age",required = false) Integer age,
                                       @RequestParam(value = "size", required = false) String size,
                                       @RequestParam(value = "type",required = false) String type,
                                       @RequestParam(value = "priceSection",required = false) Map<String, Integer> priceSection){
        return petService.selectPet(age,size,type,priceSection);
    }

    @ApiOperation("点赞")
    @PostMapping("/upvote")
    public ResponseResult<?> upvote(@RequestBody UpvoteVo upvoteVo){
        return petService.upvote(upvoteVo);
    }

    @ApiOperation("搜索宠物类型")
    @GetMapping("/selectPetType")
    public ResponseResult<?> selectPetType(){
        return petService.selectPetType();
    }

    @ApiOperation("添加宠物类型")
    @PostMapping("/insertPetType")
    public ResponseResult<?> insertPetType(@RequestParam("petNum") Integer petNum,@RequestParam("petType") String petType){
        return petService.insertPetType(petNum,petType);
    }

    @ApiOperation("更新宠物类型")
    @PostMapping("/updatePetType")
    public ResponseResult<?> updatePetType(@RequestParam("id") Integer id,@RequestParam("petType") String petType){
        return petService.updatePetType(id,petType);
    }

    @ApiOperation("删除宠物类型")
    @PostMapping("/deletePetType")
    public ResponseResult<?> deletePetType(@RequestParam("id") Integer id){
        return petService.deletePetType(id);
    }

    @ApiOperation("查询宠物寄养剩余数量")
    @GetMapping("/selectPetCheck")
    public ResponseResult<?> selectPetCheck() {
        return petService.selectPetCheck();
    }

    @ApiOperation("宠物寄养预约")
    @PostMapping("/subscribeCheck")
    public ResponseResult<?> subscribeCheck(@RequestBody SubscribeCheckVo subscribeCheckVo, HttpServletRequest request){
        return petService.subscribeCheck(subscribeCheckVo,request);
    }

    @ApiOperation("取消宠物寄养预约")
    @PostMapping("/cancelSubscribeCheck")
    public ResponseResult<?> cancelSubscribeCheck(@RequestParam("id") Integer id){
        return petService.cancelSubscribeCheck(id);
    }

    @ApiOperation("查询所有宠物寄养预约")
    @GetMapping("/selectAllCheck")
    public ResponseResult<?> selectAllCheck(){
        return petService.selectAllCheck();
    }

    @ApiOperation("查询用户所有宠物寄养预约")
    @GetMapping("/selectCheckByUser")
    public ResponseResult<?> selectCheckByUser(HttpServletRequest request){
        return petService.selectCheckByUser(request);
    }

    @ApiOperation("更新宠物寄养预约最大数量")
    @PostMapping("/updateCheckMaxNum")
    public ResponseResult<?> updateCheckMaxNum(@RequestParam("id") Integer id,@RequestParam("maxNum") Integer maxNum){
        return petService.updateCheckMaxNum(id,maxNum);
    }

    @ApiOperation("主动更新寄养、预约的表信息")
    @GetMapping("/initiativeUpdateTable")
    public void initiativeUpdateTable(){
        petService.initiativeUpdateTable();
    }
}
